<%= simple_form_for [:admin, @product], :defaults => { :input_html => { :class => "form-control" } }, html: { multipart: true, class: 'form-horizontal' } do |f| %> 

  <%= f.input :title, label: "标题" %>
  <%= f.input :category, label: "类别", collection: Product::CATEGORIES, input_html: { :onchange => "tags(this.value)"} %>
  <%= f.input :tags, label: "标签" %>
  <%= f.input :cover, label: "封面", hint: "图片大小必须小于500k, 宽高比为330x175" %>
  <%= f.input :top, label: "置顶", :input_html => { class: "" } %>
  <%= f.input :top_cover, label: "置顶图片", hint: "图片大小必须小于1.5M, 宽高比为1200x400" %>
  <%= f.input :country, label: "国家", as: :string %>
  <%= f.input :city, label: "城市", as: :string %>
  <%= f.association :articles, collection: Article.all, label: '相关文章' %>
  <%= f.input :pdf, label: "pdf" %>
  <%= f.input :description, label: '简介', as: :text %>
  <div class="form-group string optional product_description">
    <label class="string optional col-md-2 control-label" for="product_description">
      发布时间(utc)
    </label>
    <div class="col-md-10">
      <%= f.text_field :publish_time, :class => "ui_timepicker string optional form-control" %>
    </div>
  </div>

  <%= f.input_field :content, :as => :ckeditor, :input_html => { :ckeditor => {:toolbar => 'Full'} } %>

  <%= f.button :wrapped, value: "commit" %>  
<% end %>
<% tags = Category.where(name: @product.category).first.try(:tags).to_s.split(/[,]/).uniq.compact %>
<%= javascript_tag do %>
  $('#product_article_ids').select2();

  $('#product_tags').select2({maximumSelectionSize: 3,
                              multiple: true,
                              tags: <%= tags.to_s.html_safe %> });

  function tags(category) {  
    jQuery.ajax({
      url: "/admin/products/tags",
      type: "GET",
      data: {"category" : category},
    });
  }
<% end %>


<script type="text/javascript">
  $(function () {
    $(".ui_timepicker").datetimepicker({
      showSecond: true,
      timeFormat: 'hh:mm:ss',
      stepHour: 1,
      stepMinute: 1,
      stepSecond: 1
    })
  });
</script>
